'''
Created on Jul 29, 2010

@author: behrooz
'''
from amscms.recaptcha.client import captcha
from amscms import settings

def validate_captcha(request):
    captcha_response = captcha.submit(request.POST.get("recaptcha_challenge_field", None),
          request.POST.get("recaptcha_response_field", None),
          settings.RECAPTCHA_PRIVATE_KEY,
          request.META.get("REMOTE_ADDR", None))
    if captcha_response.is_valid:
        return None
    else:
        captcha_error = "&error=%s" % captcha_response.error_code
        return captcha_error
    
